<template>
	<view class="content mainpadding">
		<view class="mainpadding ffffff border flexbetween margin_bottom3">
			<view class="color_ling text_w white_nowrap margin_right3">手機號</view>
			<input class="text_a textright flex1" type="text" placeholder="請輸入手機號"
				placeholder-style="font-size: 28rpx;font-weight: 500;color: #999999;" v-model="mobile">
		</view>
		<view class="mainpadding ffffff border flexbetween margin_bottom3">
			<view class="color_ling text_w white_nowrap margin_right3">原密碼</view>
			<input class="text_a textright flex1" type="password" placeholder="請輸入原密碼"
				placeholder-style="font-size: 28rpx;font-weight: 500;color: #999999;" v-model="oldpassword">
		</view>
		<view class="mainpadding ffffff border flexbetween margin_bottom3">
			<view class="color_ling text_w white_nowrap margin_right3">新密碼</view>
			<input class="text_a textright flex1" type="password" placeholder="請輸入新密碼"
				placeholder-style="font-size: 28rpx;font-weight: 500;color: #999999;" v-model="newpassword">
		</view>
		<view class="mainpadding ffffff border flexbetween margin_bottom3">
			<view class="color_ling text_w white_nowrap margin_right3">確認新密碼</view>
			<input class="text_a textright flex1" type="password" placeholder="請再次輸入新密碼"
				placeholder-style="font-size: 28rpx;font-weight: 500;color: #999999;" v-model="confirmNewpassword">
		</view>
		<view class="footer">
			<view class="footerButton" @click="confirmRevise">
				確認修改
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: "", //手機號
				oldpassword:"",//原密碼
				newpassword: "", //新密碼
				confirmNewpassword:"",//確認新密碼
			}
		},
		methods: {
			async confirmRevise() { //確認修改
				// if (!this.mobile.match(/^1\d{10}$/)) {
				// 	this.http.toast("請輸入正确的手機號碼！")
				// 	return false
				// }
				if (!this.oldpassword) {
					this.http.toast("請輸入原密碼！")
					return false
				}
				if (!this.newpassword) {
					this.http.toast("請輸入新密碼！")
					return false
				}
				if (!this.confirmNewpassword) {
					this.http.toast("請再次輸入新密碼！")
					return false
				}
				if (this.confirmNewpassword!=this.newpassword) {
					this.http.toast("两次新密碼輸入不一致！")
					return false
				}
				let res = await this.http.request('/api/user/resetoldpwd', 'POST', {
					mobile: this.mobile,
					oldpassword: this.oldpassword,
					newpassword: this.newpassword
				})
				if (res.code == 1) {
					this.http.toast(res.msg);
					setTimeout(() => {
						uni.navigateBack(1)
					}, 1000)
				} else {
					this.http.toast(res.msg);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>